package com.example.test84;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class BookAdapter extends BaseAdapter {

    private List<Book> books;
    private Context context;

    public BookAdapter(List<Book> books, Context context) {
        this.books = books;
        this.context = context;
    }

    @Override
    public int getCount() {
        return books.size();
    }
    @Override
    public Object getItem(int position) {
        return position;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.book_item, parent, false);
        }

        TextView bookdetail = (TextView) convertView.findViewById(R.id.book_detail);
        bookdetail.setText(
                books.get(position).toString() + "category_name:" + books.get(position).getCategory_name() +
                        ",category_code:" +books.get(position).getCategroy_code()
        );

        return convertView;

    }
}
